package com.wei.czz.framework.store.manager;

import com.wei.czz.common.dto.common.GroupValue;
import com.wei.czz.common.dto.store.*;
import com.wei.czz.common.dto.store.audit.AuditReplyDto;
import com.wei.czz.common.dto.store.audit.AuditStoreDto;
import com.wei.czz.common.enums.CommonEnum;
import com.wei.czz.common.enums.common.multiDIct.MultiDictEnum;
import com.wei.czz.common.enums.ResultEnum;
import com.wei.czz.common.enums.store.StoreStatusEnum;
import com.wei.czz.common.enums.store.StoreSubmitTypeEnum;
import com.wei.czz.common.exception.CzzException;
import com.wei.czz.common.po.UserPo;
import com.wei.czz.common.tool.PageDto;
import com.wei.czz.common.utils.SecurityUtils;
import com.wei.czz.common.vo.store.*;
import com.wei.czz.framework.common.service.SnowflakeService;
import com.wei.czz.framework.common.service.AsyncService;
import com.wei.czz.framework.common.service.MultiDictService;
import com.wei.czz.framework.common.service.RegionCodeService;
import com.wei.czz.framework.store.entity.AuditStoreEntity;
import com.wei.czz.framework.store.entity.StoreAccountEntity;
import com.wei.czz.framework.store.entity.StoreBossEntity;
import com.wei.czz.framework.store.entity.StoreEntity;
import com.wei.czz.framework.store.service.*;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2023-11-22 17:53:18
 * className: StoreManager
 * version: 1.0
 * description:
 */
@Component
@AllArgsConstructor
public class StoreManager {

    private static final Logger log = LoggerFactory.getLogger(StoreManager.class);

    private final PreStoreService preStoreService;

    private final StoreService storeService;

    private final StoreAccountService storeAccountService;

    private final StoreBossService storeBossService;

    private final AuditStoreService auditStoreService;

    private final AssignStoreService assignStoreService;

    private final RegionCodeService regionCodeService;

    private final MultiDictService multiDictService;

    private final SnowflakeService snowflakeService;

    private final RedissonClient redissonClient;

    private final AsyncService asyncService;

    @Transactional
    public StoreSaveDto saveNewStore(StoreSaveVo storeSaveVo) {

        StoreVo storeVo = storeSaveVo.getStoreVo();
        StoreAccountVo storeAccountVo = storeSaveVo.getStoreAccountVo();
        StoreBossVo storeBossVo = storeSaveVo.getStoreBossVo();

        /*
            1、校验保存数量
         */
        if (Objects.isNull(storeVo.getId())) {
            Integer count = storeService.getUserStoreCount(StoreStatusEnum.SAVE.getValue());
            if (count.compareTo(20) > 0) {
                log.info("保存中的商店不能超过20个");
                throw new CzzException(ResultEnum.REQUEST_FAIL.getCode(), "保存中的商店不能超过20个");
            }
        }

        /*
            2、添加商店
         */
        Long storeId = storeService.saveStore(storeVo);
        storeAccountVo.setStoreId(storeId);
        storeBossVo.setStoreId(storeId);

        /*
            3、添加商店账户
         */
        Long storeAccountId = storeAccountService.saveStoreAccount(storeAccountVo);

        /*
            4、添加商店老板
         */
        Long storeBossId = storeBossService.saveStoreBoss(storeBossVo);

        /*
            5、添加用户商店前置
         */
        preStoreService.savePreStore(storeVo.getBusinessId(), storeId);

        StoreSaveDto storeSaveDto = new StoreSaveDto();
        storeSaveDto.setStoreId(storeId.toString())
                .setStoreAccountId(storeAccountId.toString())
                .setStoreBossId(storeBossId.toString());
        return storeSaveDto;
    }

    @Transactional
    public void submitStore(StoreSaveVo storeSaveVo) {
        StoreVo storeVo = storeSaveVo.getStoreVo();
        StoreAccountVo storeAccountVo = storeSaveVo.getStoreAccountVo();
        StoreBossVo storeBossVo = storeSaveVo.getStoreBossVo();

        /*
            修改商店状态
         */
        if (Objects.nonNull(storeVo.getId())) {
            // 获取操作用户
            UserPo userPo = SecurityUtils.getUser();
            Date date = new Date();

            StoreEntity store = new StoreEntity();
            store.setId(storeVo.getId())
                .setStatus(StoreStatusEnum.SUBMIT.getValue())
                .setUpdateTime(date)
                .setUpdateUser(userPo.getUsername())
                .setUpdateUserId(userPo.getUserId());
            int count = storeService.updateStore(store);
            if (count == 0) {
                throw new CzzException(ResultEnum.REQUEST_FAIL.getCode(), "商店不存在，请确认");
            }
        }

        /*
            提交商店
         */
        Long storeId = storeService.submitStore(storeVo);
        // 将id置空，添加新数据
        storeAccountVo.setId(null);
        storeAccountVo.setStoreId(storeId);
        storeBossVo.setId(null);
        storeBossVo.setStoreId(storeId);

        /*
            添加商店账户
         */
        storeAccountService.saveStoreAccount(storeAccountVo);

        /*
            添加商店老板
         */
        storeBossService.saveStoreBoss(storeBossVo);

        /*
            添加用户商店前置
         */
        preStoreService.savePreStore(storeVo.getBusinessId(), storeId);

        /*
            添加商店审核分单
         */
        assignStoreService.saveAssignStore(storeId, StoreSubmitTypeEnum.SUBMIT_STORE.getValue());

    }

    @Transactional
    public String fastSubmitStore(Long id) {

        /*
            校验商店基础数据
         */
        StoreEntity store = storeService.getStore(id);

        String message = this.checkStore(store);
        if (StringUtils.isNotBlank(message)) {
            log.info("商店基础数据不满足条件");
            return message;
        }

        /*
            校验商店账户数据
         */
        StoreAccountEntity storeAccount = storeAccountService.getStoreDefaultAccount(id);

        message = this.checkStoreAccount(storeAccount);
        if (StringUtils.isNotBlank(message)) {
            log.info("商店账户数据不满足条件");
            return message;
        }

        /*
            校验商店老板数据
         */
        StoreBossEntity storeBoss = storeBossService.getStoreDefaultBoss(id);

        message = this.checkStoreBoss(storeBoss);
        if (StringUtils.isNotBlank(message)) {
            log.info("商店老板数据不满足条件");
            return message;
        }

        /*
            商店提交审核
         */
        Long storeId = storeService.fastSubmitStore(store);
        storeAccount.setStoreId(storeId);
        storeBoss.setStoreId(storeId);

        /*
            添加商店账户
         */
        Long storeAccountId = storeAccountService.saveStoreAccount(storeAccount);

        /*
            添加商店老板
         */
        Long storeBossId = storeBossService.saveStoreBoss(storeBoss);

        log.info("快速提交商店数据。storeId={} storeAccountId={} storeBossId={}", storeId, storeAccountId, storeBossId);

        /*
            更新用户商店前置
         */
        preStoreService.savePreStore(store.getBusinessId(), storeId);

        /*
            添加商店审核分单
         */
        assignStoreService.saveAssignStore(storeId, StoreSubmitTypeEnum.SUBMIT_STORE.getValue());

        return null;
    }

    public StoreIndexEnumDto getStoreIndexEnums() {
        StoreIndexEnumDto storeIndexEnumDto = new StoreIndexEnumDto();

        storeIndexEnumDto.setMainClassList(multiDictService.getDictTree(MultiDictEnum.STORE_CLASS.getValue(),
                Integer::parseInt));
        storeIndexEnumDto.setStatusEnumList(StoreStatusEnum.getStatusEnumList());

        return storeIndexEnumDto;
    }

    public StoreAddEnumDto getStoreAddEnums() {
        StoreAddEnumDto storeAddEnumDto = new StoreAddEnumDto();

        storeAddEnumDto.setBusinessId(snowflakeService.find());
        storeAddEnumDto.setProvinceList(regionCodeService.getProvinceList());
        storeAddEnumDto.setBankCityList(regionCodeService.getCityList());
        storeAddEnumDto.setMainClassList(multiDictService.getDictTree(MultiDictEnum.STORE_CLASS.getValue(),
                Integer::parseInt));

        return storeAddEnumDto;
    }

    public StoreModifyEnumDto getStoreModifyEnums(Long id) {
        StoreModifyEnumDto storeModifyEnumDto = new StoreModifyEnumDto();

        /*
            获取商店
         */
        StoreEntity store = storeService.getStore(id);

        storeModifyEnumDto.setProvinceList(regionCodeService.getProvinceList());
        storeModifyEnumDto.setCityList(regionCodeService.getChildrenList(store.getAddressProvince()));
        storeModifyEnumDto.setDistrictList(regionCodeService.getChildrenList(store.getAddressCity()));
        storeModifyEnumDto.setStreetList(regionCodeService.getChildrenList(store.getAddressDistrict()));
        storeModifyEnumDto.setBankCityList(regionCodeService.getCityList());
        storeModifyEnumDto.setMainClassList(multiDictService.getDictTree(MultiDictEnum.STORE_CLASS.getValue(),
                Integer::parseInt));

        return storeModifyEnumDto;
    }

    public PageDto<StoreListDto> getStorePageList(StoreFormVo storeFormVo) {
        // 获取正在操作的用户主键
        Long optUserId = SecurityUtils.getUserId();

        storeFormVo.setUserId(optUserId);
        storeFormVo.setDeleteStatus(CommonEnum.ZERO.getValue());

        /*
            1、分页查询商店
         */
        PageDto<StoreEntity> pageDto = storeService.getStorePageList(storeFormVo);
        if (pageDto.isEmpty()) {
            return pageDto.rebuild();
        }
        List<StoreEntity> data = pageDto.getList();
        List<Long> storeIdList = data.stream().map(StoreEntity::getId).collect(Collectors.toList());

        /*
            2、查询商店账户
         */
        List<StoreAccountEntity> storeAccountList = storeAccountService.getStoreDefaultAccountList(storeIdList);
        Map<Long, StoreAccountEntity> storeAccountMap = storeAccountList.stream()
                .collect(Collectors.toMap(StoreAccountEntity::getStoreId, Function.identity(), (o1, o2) -> o1));
        /*
            3、查询商店老板
         */
        List<StoreBossEntity> storeBossList = storeBossService.getStoreDefaultBossList(storeIdList);
        Map<Long, StoreBossEntity> storeBossMap = storeBossList.stream()
                .collect(Collectors.toMap(StoreBossEntity::getStoreId, Function.identity(), (o1, o2) -> o1));

        List<StoreListDto> storeListDtoList = data.stream()
                .map(store -> this.newStoreDto(store, storeAccountMap.get(store.getId()), storeBossMap.get(store.getId())))
                .collect(Collectors.toList());
        // 封装返回
        return new PageDto<>(storeListDtoList, pageDto.getTotalNum(), storeFormVo.getPage(), storeFormVo.getLimit());
    }

    public StoreDetailDto getStoreDetail(Long id, Boolean isFirst) {

        // 地区码code集合
        Set<Integer> regionCodeSet = new HashSet<>();
        // 商店分类
        Set<String> storeClassSet = new HashSet<>();

        /*
            获取商店基础数据
         */
        StoreEntity store = storeService.getStore(id);

        // 收集地区码
        regionCodeSet.add(store.getAddressProvince());
        regionCodeSet.add(store.getAddressCity());
        regionCodeSet.add(store.getAddressDistrict());
        regionCodeSet.add(store.getAddressStreet());

        // 收集商店分类
        storeClassSet.add(store.getMainClass().toString());
        storeClassSet.add(store.getSubClass().toString());

        /*
            获取商店账户数据
         */
        List<StoreAccountEntity> storeAccountList = storeAccountService.getStoreAccountList(id);
        List<StoreAccountViewDto> storeAccountDtoList = new ArrayList<>(storeAccountList.size());
        boolean noAuditAccount = true;
        for (StoreAccountEntity storeAccount : storeAccountList) {
            // 收集地区码
            regionCodeSet.add(storeAccount.getBankCity());

            storeAccountDtoList.add(StoreAccountViewDto.map(storeAccount));

            noAuditAccount = !CommonEnum.ZERO.getValue().equals(storeAccount.getAuditStatus());
        }

        /*
            获取商店老板数据
         */
        List<StoreBossEntity> storeBossList = storeBossService.getStoreBossList(id);
        List<StoreBossDto> storeBossDtoList = new ArrayList<>(storeBossList.size());
        boolean noAuditBoss = true;
        for (StoreBossEntity storeBoss : storeBossList) {
            storeBossDtoList.add(StoreBossDto.map(storeBoss));

            noAuditBoss = !CommonEnum.ZERO.getValue().equals(storeBoss.getAuditStatus());
        }

        /*
            获取商店所有历史审核通过版本
         */
        List<StoreDto> storeDtoList = Collections.emptyList();
        if (isFirst) {
            List<StoreEntity> storeList = storeService.getFinishStoreList(store.getBusinessId());
            if (!storeList.isEmpty()) {
                // 映射
                storeDtoList = storeList.stream().map(StoreDto::map).collect(Collectors.toList());
            }
        }

        /*
            获取商店审核记录
         */
        List<GroupValue<AuditStoreDto>> auditGroupList = Collections.emptyList();
        if (isFirst) {
            List<AuditStoreEntity> auditStoreList = auditStoreService.getAuditStoreList(store.getBusinessId(),
                    null, null);
            if (!auditStoreList.isEmpty()) {
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

                auditGroupList = auditStoreList.stream()
                        .map(AuditStoreDto::map)
                        .collect(Collectors.groupingBy(auditStore -> dateFormat.format(auditStore.getCreateTime())))
                        .entrySet()
                        .stream()
                        .map(entry -> new GroupValue<>(entry.getKey(), entry.getValue()))
                        .sorted(Comparator.comparing(GroupValue::getName, Comparator.reverseOrder()))
                        .collect(Collectors.toList());
            }
        }

        /*
            获取地区名称
         */
        Map<Integer, String> regionNameMap = regionCodeService.batchGetName(regionCodeSet);

        /*
            获取商店分类
         */
        Map<Integer, String> storeClassMap = multiDictService.batchGetName(MultiDictEnum.STORE_CLASS.getValue(),
                storeClassSet, Integer::parseInt);

        StoreViewDto storeViewDto = StoreViewDto.map(store);
        storeViewDto.setAddressProvinceName(regionNameMap.get(storeViewDto.getAddressProvince()))
                .setAddressCityName(regionNameMap.get(storeViewDto.getAddressCity()))
                .setAddressDistrictName(regionNameMap.get(storeViewDto.getAddressDistrict()))
                .setAddressStreetName(regionNameMap.get(storeViewDto.getAddressStreet()))
                .setMainClassName(storeClassMap.get(storeViewDto.getMainClass()))
                .setSubClassName(storeClassMap.get(storeViewDto.getSubClass()));

        for (StoreAccountViewDto storeAccountViewDto : storeAccountDtoList) {
            storeAccountViewDto.setBankCityName(regionNameMap.get(storeAccountViewDto.getBankCity()));
        }

        StoreDetailDto storeDetailDto = new StoreDetailDto();
        storeDetailDto.setStoreViewDto(storeViewDto)
                .setStoreAccountDtoList(storeAccountDtoList)
                .setStoreBossDtoList(storeBossDtoList)
                .setHistoryFinishList(storeDtoList)
                .setAuditGroupList(auditGroupList)
                .setNoAuditAccount(noAuditAccount)
                .setNoAuditBoss(noAuditBoss);
        return storeDetailDto;
    }

    public StoreModifyDetailDto getEditStoreDetail(Long id) {

        /*
            获取商店基础数据
         */
        StoreEntity store = storeService.getStore(id);

        /*
            获取商店账户数据
         */
        StoreAccountEntity storeAccount = storeAccountService.getStoreDefaultAccount(id);

        /*
            获取商店老板数据
         */
        StoreBossEntity storeBoss = storeBossService.getStoreDefaultBoss(id);

        /*
             获取商店审核回复数据
         */
        AuditReplyDto auditReplyDto = null;
        if (StoreStatusEnum.AUDIT_RETURN.getValue().equals(store.getStatus())
                || StoreStatusEnum.MODIFY_RETURN.getValue().equals(store.getStatus())) {
            AuditStoreEntity auditStore = auditStoreService.getAuditReject(id);

            if (Objects.nonNull(auditStore)) {
                auditReplyDto = new AuditReplyDto();
                auditReplyDto.setAuditTime(auditStore.getCreateTime())
                        .setAuditRemark(auditStore.getAuditRemark());
            }
        }

        StoreModifyDetailDto storeModifyDetailDto = new StoreModifyDetailDto();
        storeModifyDetailDto.setStoreDto(StoreDto.map(store))
                .setStoreAccountDto(StoreAccountDto.map(storeAccount))
                .setStoreBossDto(StoreBossDto.map(storeBoss))
                .setAuditReplyDto(auditReplyDto);
        return storeModifyDetailDto;
    }

    @Transactional
    public void withdrawAudit(Long id) {
        // 获取操作用户
        UserPo userPo = SecurityUtils.getUser();
        Date date = new Date();

        /*
            获取商店
         */
        StoreEntity store = storeService.getStore(id);
        log.info("商店撤销审核之商店状态。status={}", StoreStatusEnum.getName(store.getStatus()));
        if (StoreStatusEnum.AUDIT_RETURN.getValue().equals(store.getStatus())) {
            log.info("商店已被审核退回");
            throw new CzzException(ResultEnum.REFRESH.getCode(), "商店已被审核退回，撤销失败");
        }
        if (StoreStatusEnum.MODIFY_RETURN.getValue().equals(store.getStatus())) {
            log.info("商店已被审核退回修改");
            throw new CzzException(ResultEnum.REFRESH.getCode(), "商店已被审核退回修改，撤销失败");
        }
        if (StoreStatusEnum.FINISH.getValue().equals(store.getStatus())) {
            log.info("商店已被审核通过");
            throw new CzzException(ResultEnum.REFRESH.getCode(), "商店已被审核通过，撤销失败");
        }

        if (StoreStatusEnum.SUBMIT.getValue().equals(store.getStatus())) {
            log.info("商店回退到保存状态");
            /*
                变更商店状态
             */
            StoreEntity updateStore = new StoreEntity();
            updateStore.setId(id)
                    .setStatus(StoreStatusEnum.SAVE.getValue())
                    .setUpdateTime(date)
                    .setUpdateUser(userPo.getUsername())
                    .setUpdateUserId(userPo.getUserId());
            storeService.updateStore(updateStore);
        }
        if (StoreStatusEnum.MODIFY.getValue().equals(store.getStatus())) {
            log.info("商店回退到审核通过状态");
            Long maxId = storeService.getLastId(store.getBusinessId(), StoreStatusEnum.FINISH.getValue());
            if (Objects.isNull(maxId)) {
                log.error("商店审核通过主键获取失败。id={} businessId={}", id, store.getBusinessId());
                throw new CzzException(ResultEnum.SERVICE_FAIL.getCode(), "商店没有可回退版本，不满足撤销条件，撤销失败");
            }
            /*
                更新用户商店前置
             */
            preStoreService.savePreStore(store.getBusinessId(), maxId);

            /*
                删除商店
             */
            StoreEntity updateStore = new StoreEntity();
            updateStore.setId(id)
                    .setDeleteStatus(CommonEnum.ONE.getValue())
                    .setUpdateTime(date)
                    .setUpdateUser(userPo.getUsername())
                    .setUpdateUserId(userPo.getUserId());
            storeService.updateStore(store);
        }

        /*
            删除商店分单数据
         */
        List<Integer> submitTypeList = Arrays.asList(StoreSubmitTypeEnum.SUBMIT_STORE.getValue(),
                StoreSubmitTypeEnum.STORE_MODIFY.getValue());
        assignStoreService.batchDeleteAssignStore(Collections.singletonList(id), submitTypeList);

    }

    @Transactional
    public void modifyStore(StoreSaveVo storeSaveVo) {
        // 获取操作用户
        UserPo userPo = SecurityUtils.getUser();
        Date date = new Date();

        StoreVo storeVo = storeSaveVo.getStoreVo();
        StoreAccountVo storeAccountVo = storeSaveVo.getStoreAccountVo();
        StoreBossVo storeBossVo = storeSaveVo.getStoreBossVo();

        /*
            获取商店
         */
        StoreEntity store = storeService.getStore(storeVo.getId());

        /*
            修改商店状态
         */
        if (StoreStatusEnum.MODIFY_RETURN.getValue().equals(store.getStatus())) {
            store = new StoreEntity();
            store.setId(storeVo.getId())
                .setStatus(StoreStatusEnum.MODIFY.getValue())
                .setUpdateTime(date)
                .setUpdateUser(userPo.getUsername())
                .setUpdateUserId(userPo.getUserId());
            storeService.updateStore(store);
        }

        /*
            提交商店
         */
        Long storeId = storeService.modifyStore(storeVo);
        // 将id置空，添加新数据
        storeAccountVo.setId(null);
        storeAccountVo.setStoreId(storeId);
        storeBossVo.setId(null);
        storeBossVo.setStoreId(storeId);

        /*
            添加商店账户
         */
        storeAccountService.saveStoreAccount(storeAccountVo);

        /*
            添加商店老板
         */
        storeBossService.saveStoreBoss(storeBossVo);

        /*
            修改用户商店前置
         */
        preStoreService.savePreStore(storeVo.getBusinessId(), storeId);

        /*
            添加商店审核分单
         */
        assignStoreService.saveAssignStore(storeId, StoreSubmitTypeEnum.STORE_MODIFY.getValue());

        /*
             异步复制商店账户和商店老板
         */
        asyncService.execute(() -> {
            // 复制商店账户
            storeAccountService.copyStoreAccount(storeVo.getId(), storeId);
            // 复制商店老板
            storeBossService.copyStoreBoss(storeVo.getId(), storeId);
        });
    }

    @Transactional
    public void deleteStore(List<Long> idList) {
        // 正在删除商店审核的用户
        Long optUserId = SecurityUtils.getUserId();

        /*
            删除商店
         */
        storeService.batchDeleteStore(idList);

        /*
            删除用户商店前置
         */
        preStoreService.batchDeletePreStore(optUserId, idList);

        /*
            删除商店分单数据
         */
        assignStoreService.batchDeleteAssignStore(idList, null);
    }

    /**
     * 商店封装
     * @param store        商店
     * @param storeAccount 商店账户
     * @param storeBoss    商店老板
     * @return 封装结果
     */
    private StoreListDto newStoreDto(StoreEntity store, StoreAccountEntity storeAccount, StoreBossEntity storeBoss) {
        StoreListDto storeListDto = new StoreListDto();
        storeListDto.setId(store.getId().toString())
                .setBusinessId(store.getBusinessId().toString())
                .setName(store.getName())
                .setArea(CommonEnum.filterDefault(store.getArea(), area -> String.valueOf((double) area / 100)))
                .setMainClass(CommonEnum.filterDefault(store.getMainClass()))
                .setSubClass(CommonEnum.filterDefault(store.getSubClass()))
                .setStatus(CommonEnum.filterDefault(store.getStatus()))
                .setCreateTime(store.getCreateTime());
        if (Objects.nonNull(storeAccount)) {
            if (CommonEnum.ZERO.getValue().equals(storeAccount.getType())) {
                storeListDto.setAccountName(storeAccount.getEnterpriseName());
            } else if (CommonEnum.ONE.getValue().equals(storeAccount.getType())){
                storeListDto.setAccountName(storeAccount.getName());
            }
            storeListDto.setAccountStatus(storeAccount.getStatus());
        }
        if (Objects.nonNull(storeBoss)) {
            storeListDto.setBossName(storeBoss.getName())
                    .setBossStatus(storeBoss.getStatus());
        }
        return storeListDto;
    }

    /**
     * 校验商店基础数据是否满足提交条件
     * @param store 商店对象
     * @return 错误提示
     */
    private String checkStore(StoreEntity store) {
        if (CommonEnum.MINUS_ONE.getValue().equals(store.getAddressProvince())) {
            return "商店所属省份未选择";
        }
        if (CommonEnum.MINUS_ONE.getValue().equals(store.getAddressCity())) {
            return "商店所属城市未选择";
        }
        if (CommonEnum.MINUS_ONE.getValue().equals(store.getAddressDistrict())) {
            return "商店所属区县未选择";
        }
        if (StringUtils.isBlank(store.getAddress())) {
            return "商店详细门牌号地址未填写";
        }
        if (CommonEnum.MINUS_ONE.getValue().equals(store.getArea())) {
            return "商店面积未填写";
        }
        if (CommonEnum.MINUS_ONE.getValue().equals(store.getMainClass())) {
            return "商店经营大类未选择";
        }
        if (CommonEnum.MINUS_ONE.getValue().equals(store.getSubClass())) {
            return "商店经营小类未选择";
        }
        return null;
    }

    /**
     * 校验商店账户数据是否满足提交条件
     * @param storeAccount 商店账户对象
     * @return 错误提示
     */
    private String checkStoreAccount(StoreAccountEntity storeAccount) {
        if (Objects.isNull(storeAccount.getType())) {
            return "商店账户类型未选择";
        }
        if (CommonEnum.ZERO.getValue().equals(storeAccount.getType())) {
            // 对公
            if (StringUtils.isBlank(storeAccount.getEnterpriseName())) {
                return "商店账户所用公司名称未填写";
            }
            if (StringUtils.isBlank(storeAccount.getEnterpriseNo())) {
                return "商店账户所用公司社会统一信用代码未填写";
            }
        } else {
            // 对私
            if (StringUtils.isBlank(storeAccount.getName())) {
                return "商店账户名称未填写";
            }
            if (StringUtils.isBlank(storeAccount.getIdCard())) {
                return "商店账户身份证号未填写";
            }
        }
        if (StringUtils.isBlank(storeAccount.getBankNo())) {
            return "商店账户银行卡号未填写";
        }
        if (StringUtils.isBlank(storeAccount.getBankName())) {
            return "商店账户银行名称未填写";
        }
        if (StringUtils.isBlank(storeAccount.getBankBranchName())) {
            return "商店账户支行名称未填写";
        }
        if (StringUtils.isBlank(storeAccount.getBankMobile())) {
            return "商店账户银行预留手机号未填写";
        }
        if (Objects.isNull(storeAccount.getBankCity())) {
            return "商店账户银行所在城市未选择";
        }
        return null;
    }

    /**
     * 校验商店老板数据是否满足提交条件
     * @param storeBoss 商店老板对象
     * @return 错误提示
     */
    private String checkStoreBoss(StoreBossEntity storeBoss) {
        if (StringUtils.isBlank(storeBoss.getName())) {
            return "商店老板名称未填写";
        }
        if (Objects.isNull(storeBoss.getGender())) {
            return "商店老板性别未选择";
        }
        if (StringUtils.isBlank(storeBoss.getIdCard())) {
            return "商店老板身份证号未填写";
        }
        if (StringUtils.isBlank(storeBoss.getMobile())) {
            return "商店老板手机号未填写";
        }
        return null;
    }
}
